﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using Inspire.Entities;
using Inspire.DataStructures;

namespace Inspire.Utility
{
    /// <summary>
    /// CustomFieldTemplateSelector: Used by pages to populate a custom field data grid with user controls appropriate to the type of custom field.
    /// </summary>
    class CustomFieldTemplateSelector : DataTemplateSelector
    {
        private bool _isEdit = false;
        /// <summary>
        /// Determines if this should return editing templates or not.
        /// </summary>
        public bool IsEdit
        {
            get
            {
                return this._isEdit;
            }
            set
            {
                this._isEdit = value;
            }
        }
        public DataTemplate StringTemplate { get; set; }
        public DataTemplate StringEditingTemplate { get; set; }
        public DataTemplate BooleanTemplate { get; set; }
        public DataTemplate IntegerTemplate { get; set; }
        public DataTemplate IntegerEditingTemplate { get; set; }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (item != null)
            {
                // If it's a BOOLEAN
                if (((NewCustomFieldSource)item).CustomFieldType.Type.Equals("Boolean"))
                {
                    return this.BooleanTemplate;
                }

                // If it's an INTEGER
                if (((NewCustomFieldSource)item).CustomFieldType.Type.Equals("Int32"))
                {
                    if (this.IsEdit)
                    {
                        return IntegerEditingTemplate;
                    }
                    else
                    {
                        return IntegerTemplate;
                    }
                }

                // If it's a STRING
                if (this.IsEdit)
                {
                    return StringEditingTemplate;
                }
                else
                {
                    return StringTemplate;
                }
            }
            return null;
        }
    }
}
